package cn.dt70.service.impl;

import cn.dt70.dao.aqbAddress.AqbAddressMapper;
import cn.dt70.pojo.AqbAddress;
import cn.dt70.service.AqbAddressService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class AqbAddressServiceImpl implements AqbAddressService {

    private static final Logger LOGGER = Logger.getLogger(AqbAddressServiceImpl.class);

    @Resource
    private AqbAddressMapper aqbAddressMapper;


    @Override
    public List<AqbAddress> getAddressByUserid(Integer userId) {
        List<AqbAddress> aqbAddressList = new ArrayList<AqbAddress>();
        try{
            aqbAddressList = aqbAddressMapper.getAddressByUserid(userId);
            if( aqbAddressList.size() <= 0){
                LOGGER.debug("AqbAddressServiceImpl 查询为空!");
            }else{
                LOGGER.debug("AqbAddressServiceImpl 查询成功!");
            }

        }catch (Exception e) {
            //e.printStackTrace();
            LOGGER.error("AqbAddressServiceImpl >>>"+e.getMessage());
        }
        return aqbAddressList;
    }

    @Override
    public AqbAddress getAddressByAddid(Integer addId) {
        AqbAddress aqbAddress = new AqbAddress();
        try{
            aqbAddress = aqbAddressMapper.getAddressByAddid(addId);
            if(  aqbAddress == null){
                LOGGER.debug("AqbAddressServiceImpl  getAddressByAddid查询为空!");
            }else{
                LOGGER.debug("AqbAddressServiceImpl  getAddressByAddid 查询成功!");
            }
        }catch (Exception e) {
            //e.printStackTrace();
            LOGGER.error("AqbAddressServiceImpl >>>"+e.getMessage());
        }
        return aqbAddress;
    }

    @Override
    public Boolean addAddress(Integer userId, String addressName, String provicace, String city, String district, String address, String phone) {
        int flag = 0 ;
        boolean newflag =false;
       try {
              flag = aqbAddressMapper.addAddress(userId,addressName,provicace,city,district,address,phone);
              if(flag > 0){
                  newflag =true;
                  LOGGER.debug("添加成功!");
              }else {
                  newflag =false;
                  LOGGER.debug("添加失败!");
              }
       }catch (Exception e) {
           //e.printStackTrace();
           LOGGER.error("添加失败！");
       }
        return newflag;
    }
}
